#######################################################################
#Name of code file: narrative_analysis.R

#Data In: narrative_data.csv

#Data Out: Figure 2
######################################################################

#Load packages
library(dplyr)
library(ggplot2)
library(readr)

#Set Working Directory
setwd("../diresta_grossman_siegel_replication/")

#Read in Data
data<-read_csv("data/narrative_data.csv")

#Plot Monthly Proportions by Narrative and Source 

#Battlefield Events

battlefield<-subset(data, narrative=="Battlefield Events")

battlefield %>% 
  ggplot() + 
  aes(x = month, y = prop, color=source) + 
  geom_point(alpha = 0.5) + 
  geom_smooth(span=1, alpha=.25, se=FALSE)+
  labs(y = "Monthly Prop. of Syria Posts", x = "Date")+
  theme_minimal(base_size=18)
ggsave("plots/Figure2_battlefield_narratives.pdf", width = 15, height = 8)

#Casualties 

casualties<-subset(data, narrative=="Civilian Casualties")

casualties %>% 
  ggplot() + 
  aes(x = month, y = prop, color=source) + 
  geom_point(alpha = 0.5) + 
  geom_smooth(span=1, alpha=.25, se=FALSE)+
  labs(y = "Monthly Prop. of Syria Posts", x = "Date")+
  theme_minimal(base_size=18)
ggsave("plots/Figure2_casualties.pdf", width = 15, height = 8)

#Humanitarian Aid

humanitarian<-subset(data, narrative=="Humanitarian Aid")

humanitarian %>% 
  ggplot() + 
  aes(x = month, y = prop, color=source) + 
  geom_point(alpha = 0.5) + 
  geom_smooth(span=1, alpha=.25, se=FALSE)+
  labs(y = "Monthly Prop. of Syria Posts", x = "Date")+
  theme_minimal(base_size=18)
ggsave("plots/Figure2_humanitarian.pdf", width = 15, height = 8)


#ISIS

isis<-subset(data, narrative=="ISIS")

isis %>% 
  ggplot() + 
  aes(x = month, y = prop, color=source) + 
  geom_point(alpha = 0.5) + 
  geom_smooth(span=1, alpha=.25, se=FALSE)+
  labs(y = "Monthly Prop. of Syria Posts", x = "Date")+
  theme_minimal(base_size=18)
ggsave("plots/Figure2_isis.pdf", width = 15, height = 8)

#Clinton/Obama

clinton_obama<-subset(data, narrative=="Clinton / Obama")

clinton_obama %>% 
  ggplot() + 
  aes(x = month, y = prop, color=source) + 
  geom_point(alpha = 0.5) + 
  geom_smooth(span=1, alpha=.25, se=FALSE)+
  labs(y = "Monthly Prop. of Syria Posts", x = "Date")+
  theme_minimal(base_size=18)
ggsave("plots/Figure2_clinton_obama.pdf", width = 15, height = 8)


#Trump

trump<-subset(data, narrative=="Trump")

trump %>% 
  ggplot() + 
  aes(x = month, y = prop, color=source) + 
  geom_point(alpha = 0.5) + 
  geom_smooth(span=1, alpha=.25, se=FALSE)+
  labs(y = "Monthly Prop. of Syria Posts", x = "Date")+
  theme_minimal(base_size=18)+
  ylim(0,1)
ggsave("plots/Figure2_trump.pdf", width = 15, height = 8)


#Refugees

refugees<-subset(data, narrative=="Refugees")

refugees %>% 
  ggplot() + 
  aes(x = month, y = prop, color=source) + 
  geom_point(alpha = 0.5) + 
  geom_smooth(span=1, alpha=.25, se=FALSE)+
  labs(y = "Monthly Prop. of Syria Posts", x = "Date")+
  theme_minimal(base_size=18)
ggsave("plots/Figure2_refugees.pdf", width = 15, height = 8)


#Diplomacy

diplomacy<-subset(data, narrative=="Diplomacy")

diplomacy %>% 
  ggplot() + 
  aes(x = month, y = prop, color=source) + 
  geom_point(alpha = 0.5) + 
  geom_smooth(span=1, alpha=.25, se=FALSE)+
  labs(y = "Monthly Prop. of Syria Posts", x = "Date")+
  theme_minimal(base_size=18)
ggsave("plots/Figure2_diplomacy.pdf", width = 15, height = 8)

#BLM

blm<-subset(data, narrative=="BLM")

blm %>% 
  ggplot() + 
  aes(x = month, y = prop, color=source) + 
  geom_point(alpha = 0.5) + 
  geom_smooth(span=1, alpha=.25, se=FALSE)+
  labs(y = "Monthly Prop. of Syria Posts", x = "Date")+
  theme_minimal(base_size=18)
ggsave("plots/Figure2_blm.pdf", width = 15, height = 8)




